package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ResReview;
import com.ruoyi.system.service.IResReviewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 餐馆评论Controller
 * 
 * @author ruoyi
 * @date 2025-06-01
 */
@RestController
@RequestMapping("/system/resreview")
public class ResReviewController extends BaseController
{
    @Autowired
    private IResReviewService resReviewService;

    /**
     * 查询餐馆评论列表
     */
//    @PreAuthorize("@ss.hasPermi('system:resreview:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResReview resReview)
    {
        System.out.println("resReview:" + resReview);
        startPage();
        List<ResReview> list = resReviewService.selectResReviewList(resReview);
        System.out.println("------------------" + list);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:resreview:list')")
    @GetMapping("/list1")
    public TableDataInfo list1(ResReview resReview, Long userId)
    {
        startPage();
        List<ResReview> list = resReviewService.selectResReviewListByUserId(resReview, userId);
        System.out.println("------------------" + list);
        return getDataTable(list);
    }

    /**
     * 导出餐馆评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:resreview:export')")
    @Log(title = "餐馆评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResReview resReview)
    {
        List<ResReview> list = resReviewService.selectResReviewList(resReview);
        ExcelUtil<ResReview> util = new ExcelUtil<ResReview>(ResReview.class);
        util.exportExcel(response, list, "餐馆评论数据");
    }

    /**
     * 获取餐馆评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:resreview:query')")
    @GetMapping(value = "/{reviewId}")
    public AjaxResult getInfo(@PathVariable("reviewId") Long reviewId)
    {
        return success(resReviewService.selectResReviewByReviewId(reviewId));
    }

    /**
     * 新增餐馆评论
     */
    @PreAuthorize("@ss.hasPermi('system:resreview:add')")
    @Log(title = "餐馆评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResReview resReview)
    {
        return toAjax(resReviewService.insertResReview(resReview));
    }

    /**
     * 修改餐馆评论
     */
    @PreAuthorize("@ss.hasPermi('system:resreview:edit')")
    @Log(title = "餐馆评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResReview resReview)
    {
        return toAjax(resReviewService.updateResReview(resReview));
    }

    /**
     * 删除餐馆评论
     */
    @PreAuthorize("@ss.hasPermi('system:resreview:remove')")
    @Log(title = "餐馆评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reviewIds}")
    public AjaxResult remove(@PathVariable Long[] reviewIds)
    {
        return toAjax(resReviewService.deleteResReviewByReviewIds(reviewIds));
    }
}
